package com.mingmen.supplier.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.supplier.R;
import com.mingmen.supplier.defineview.GlideRoundTransform;
import com.mingmen.supplier.httpconfig.AppConfig;
import com.mingmen.supplier.model.DingDanZongModel;
import com.mingmen.supplier.model.WeiHuModel;

import java.util.ArrayList;
import java.util.List;


public class DingDanZongListAdapter extends RecyclerView.Adapter<DingDanZongListAdapter.ViewHolder> {
    List<DingDanZongModel.DataBean> myLiveList = new ArrayList<>();
    Context mContext;
    private OnItemClickListener mOnItemClickListener;
    private int checkedPosition = -1;

    //    WeiHuModel.DataBean
    //recycleview标签
    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int pos, List<DingDanZongModel.DataBean> myLiveList);
    }


    public DingDanZongListAdapter(Context context, List<DingDanZongModel.DataBean> myLiveList) {
        this.mContext = context;
        this.myLiveList = myLiveList;

    }

    public void setDataList(List<DingDanZongModel.DataBean> list) {
        myLiveList = list;

        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dingdanzong, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        DingDanZongModel.DataBean dataBean = myLiveList.get(position);
        holder.commodityName.setText(dataBean.getCommodityName());
        holder.text_spec.setText("规格:  " + dataBean.getSpec());
        holder.confirmPrice.setText("报价:    " + dataBean.getConfirmPrice()+"元");
        holder.confirmAmount.setText("数量:     " + dataBean.getConfirmAmount());
        Log.d("confirmPrice",dataBean.getConfirmPrice()+"");
        Log.d("confirmAmount",dataBean.getConfirmAmount()+"");

        Glide.with(mContext).load(AppConfig.IMGURL + dataBean.getPicture()).dontAnimate().placeholder(R.mipmap.default_pic).error(R.mipmap.default_pic).transform(new GlideRoundTransform(mContext, 5)).into(holder.img_pic);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });
        holder.text_manager.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });
    }

    @Override
    public int getItemCount() {
        return myLiveList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView commodityName;
        LinearLayout content;
        TextView text_manager;
        TextView text_spec;
        TextView confirmPrice;
        TextView confirmAmount;
        ImageView img_pic;

        public ViewHolder(View itemView) {
            super(itemView);

            commodityName = (TextView) itemView.findViewById(R.id.commodityName);
            content = itemView.findViewById(R.id.content);
            text_manager = itemView.findViewById(R.id.text_manager);
            text_spec = itemView.findViewById(R.id.text_spec);
            confirmPrice = itemView.findViewById(R.id.confirmPrice);
            confirmAmount = itemView.findViewById(R.id.confirmAmount);
            img_pic = itemView.findViewById(R.id.img_pic);
        }
    }


}
